//
//  YHTimeCell.m
//  ZhuKuang
//
//  Created by jjkj on 17/7/11.
//  Copyright © 2017年 jjkj. All rights reserved.
//

#import "YHTimeCell.h"
@interface YHTimeCell()
{
    CABasicAnimation * _animation;
}
/**时间*/
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
/**状态*/
@property (weak, nonatomic) IBOutlet UIImageView *stateImgView;
/**类型*/
@property (weak, nonatomic) IBOutlet UILabel *stateNameLabel;
/**量*/
@property (weak, nonatomic) IBOutlet UILabel *stateNumlabel;
/**车*/
@property (weak, nonatomic) IBOutlet UILabel *detailLable;
/**报警按钮*/
@property (weak, nonatomic) IBOutlet UIImageView *alarmBtn;

/**
 *  标签按钮点击事件
 */
-(IBAction)detailBtnAction:(UIButton *)sender;
/**
 *  报警按钮点击事件
 */
-(IBAction)alarmBtnAction:(UIButton *)sender;
@end
@implementation YHTimeCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setIolModel:(YHTimeIolModel *)iolModel
{
    _iolModel = iolModel;
    NSDate * time = [CommClass dateFormatTimeStamp:iolModel.time timeFormat:TIME_FORMATTER_24];
    self.timeLabel.text = [CommClass formatTimeStamp:time timeFormat:TIME_FORMATTER_HM];
    if ([iolModel.type containsString:@"入油"]) {
        self.stateImgView.highlighted = YES;
    }else{
        self.stateImgView.highlighted = NO;
    }
    self.stateNameLabel.text = iolModel.type;
    if ([iolModel.iol floatValue] != 0) {
        self.stateNumlabel.text = [NSString stringWithFormat:@"%.1fL",[iolModel.iol floatValue]];
    }else{
        self.stateNumlabel.text =  @"0L";
    }
    
    self.detailLable.text = iolModel.car;
    if ([iolModel.isException integerValue] == globalNum1) {
        [self.alarmBtn.layer addAnimation:[self opacityForever_Animation:0.7] forKey:self.timeLabel.text];
    }else{
        [self.alarmBtn.layer removeAllAnimations];
    }
}

/**
 *  标签按钮点击事件
 */
-(IBAction)detailBtnAction:(UIButton *)sender
{
    if (self.detailClickBlock) {
        self.detailClickBlock();
    }
}
/**
 *  报警按钮点击事件
 */
-(IBAction)alarmBtnAction:(UIButton *)sender
{
    if (self.singleClickBlock) {
        self.singleClickBlock();
    }
}

#pragma mark === 永久闪烁的动画 ======
-(CABasicAnimation *)opacityForever_Animation:(float)time
{
    if (!_animation) {
        _animation = [CABasicAnimation animationWithKeyPath:@"opacity"];//必须写opacity才行。
        _animation.fromValue = [NSNumber numberWithFloat:1.0f];
        _animation.toValue = [NSNumber numberWithFloat:0.0f];//这是透明度。
        _animation.autoreverses = YES;
        _animation.duration = time;
        _animation.repeatCount = MAXFLOAT;
        _animation.removedOnCompletion = NO;
        _animation.fillMode = kCAFillModeForwards;
        //    animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];///没有的话是均匀的动画。
    }
    return _animation;
}

@end
